package 力扣日常刷题.木22二月.第20天226;

/**
 * @author 帅小伙
 * @date 2022/2/26
 * @description
 */
public class Demo156最长连续子数组 {


    public int GetMaxConsecutiveOnes (int[] arr, int k) {
        // write code here
        if(arr.length <= k) return arr.length;
        int ans = 0, i = 0;


        while(i < arr.length - k) {
            int count = 0;
            int j = i;
            for (; j < arr.length; j++) {
                if(arr[j]!= 1) count++;
                if(count > k){
                    ans = Math.max(ans,j - i);
                }
            }
            if(j == arr.length)  ans = Math.max(ans,j - i);
            i++;
        }
        return ans;
    }
}
